package panel.viewSpots.navigation
{
	import assists.URI;
	import assists.media.SoundMedia;
	import assists.resource.ResourceLoader;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	
	import main.ClientConstants;
	
	import panel.media.MediaBtnGroup;
	import panel.media.MediaPlayProcess;
	
	public class SoundModule extends Sprite
	{
		private var _stage:Stage;
		private var _loader:ResourceLoader;
		
		private var _sound:SoundMedia;
		
		private var _process:MediaPlayProcess;

		private var _btnGroup:MediaBtnGroup;
		private var _onOpenNewSound:Function;
		public function SoundModule(stage:Stage, loader:ResourceLoader,soundMedia:SoundMedia)
		{
			_stage = stage;
			_loader = loader;
			_sound = soundMedia;
			init();
		}
		
		private function init():void
		{
			layoutUI();
			initSoundMedia();
		}
		
		
		public function playSound(value:String):void
		{
			_sound.loadSound(value);
		}
		
		private function layoutUI():void
		{
			
			_btnGroup = new MediaBtnGroup();
			_btnGroup.init(_loader,_stage);
			this.addChild(_btnGroup);
			
			_process = new MediaPlayProcess();
			
			_process.lindeWid = _stage.stageWidth - _btnGroup.width;
			_process.init(_loader,_stage);
			_process.y = _btnGroup.y;
			_process.x = _btnGroup.x + _btnGroup.width;
			this.addChild(_process);
			
		}
		
		public function set onSoundMedia(value:SoundMedia):void
		{
			_sound = value;
			initSoundMedia();
		}
		
		private function initSoundMedia():void
		{
			if(!_sound)
			{
				_process.filters = [ClientConstants.GLOBAL_FILTER_GREY];
				_btnGroup.onControlMedia = _onOpenNewSound;
				_btnGroup.hasSoundMedia = false;
				_process.mouseEnabled = false;
				return;
			}
			_btnGroup.hasSoundMedia = true;
			_process.mouseEnabled = true;
			_process.filters = [];
			_sound.onUpdate = _process.update;
			_btnGroup.onControlMedia = _sound.onControllSound;
			_process.changeProcss = _sound.updateProcess;
		}
		
		public function set onOpenNewSound(value:Function):void
		{
			_onOpenNewSound = value;
			initSoundMedia();
		}
		
		public function clear():void
		{
			_sound.clear();
		}
	}
	
}